﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using Microsoft.Practices.WizardFramework;
using Microsoft.WizardFramework;
using PrismFactory.SoftwareFactory.Views.CreateSolution;
using PrismGuidancePackage.Views.Services;
using WizardForm = Microsoft.Practices.WizardFramework.WizardForm;

namespace PrismFactory.SoftwareFactory.CustomWizardPages.CreateSolution
{
    public partial class EnsureEntlibAssembliesPathPage : CustomWizardPage
    {
        private EnsureEntlibAssembliesPathPageViewModel viewModel;

        public EnsureEntlibAssembliesPathPage()
        {
            InitializeComponent();
        }

        public EnsureEntlibAssembliesPathPage(WizardForm wizard)
            : base(wizard)
        {
            InitializeComponent();
        }

        private void CreateSolutionPageView_Load(object sender, EventArgs e)
        {
            viewModel = new EnsureEntlibAssembliesPathPageViewModel(GetService(typeof (IDictionaryService)) as IDictionaryService, new FileSystemService());
            viewModel.PropertyChanged += OnViewModelPropertyChanged;
            var view = elementHost1.Child as EnsureEntlibAssembliesPathPageView;
            if (view != null) view.DataContext = viewModel;
            Wizard.OnValidationStateChanged(this);
        }

        private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Wizard.OnValidationStateChanged(this);
        }

        public override bool IsDataValid
        {
            get
            {
                if (viewModel != null)
                {
                    return viewModel.IsValid;
                }
                return true;
            }
        }
    }
}